import { _decorator, Component, director, find, Label, Node, resources } from 'cc';
import GameController from '../script/GameController';
import { Hand } from '../prefab/Hand';
import { EventEnum } from '../script/Enum';
const { ccclass, property } = _decorator;

@ccclass('GameScene')
export class GameScene extends Component {

    private nDeck: Node = null;
    private nHand: Node = null;
    private lbScore: Label = null;
    protected onLoad(): void {

        director.on(EventEnum.SCORE_UPDATE, this.scoreUpdate, this);

        resources.preloadDir("mj");

        this.nDeck = find('nDeck', this.node);
        this.nHand = find('nHand/Hand', this.node);
        this.lbScore = find("lbScore", this.node).getComponent(Label);

        GameController.getInstance().initGame();
    }

    start() {

    }

    update(deltaTime: number) {

    }


    public onTouchChi() {
        let list = GameController.getInstance().getChiList();
        console.log(list);
        this.nHand.getComponent(Hand).sortInHand();
        GameController.getInstance().onChi(0);
    }

    public onTouchPeng() {
        this.nHand.getComponent(Hand).sortInHand();
        GameController.getInstance().onPeng();
    }

    public onTouchGang() {
        this.nHand.getComponent(Hand).sortInHand();
        GameController.getInstance().onGang();
    }

    public onSevenPair() {

        GameController.getInstance().onSevenPair();
    }

    public onTouchLong() {
        GameController.getInstance().onLong();
    }

    public scoreUpdate() {
        this.lbScore.string = GameController.getInstance().Score.toString() + "分";
    }

}

